package com.ssh;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

public class LetterCombinations_17 {
	public List<String> letterCombinations(String digits) {
        String[] s = {" "," ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
        List<String> list = new ArrayList<String>();
        if (digits.isEmpty()) {
        	return list;
        }
        l(list, new StringBuffer(), digits, s, 0);
        return list;
    }
	private void l (List<String> list, StringBuffer sb, String digits,String[] s,int x) {
		if (sb.length() == digits.length()) {
			list.add(sb.toString());
			return;
		}
		int a = Integer.parseInt(String.valueOf(digits.charAt(x)));
		for (int i = 0; i < s[a].length(); i++) {
			sb.append(s[a].charAt(i));
			System.out.println(s[a].charAt(i));
			l(list, sb, digits, s, x+1);
			sb.deleteCharAt(sb.lastIndexOf(String.valueOf(s[a].charAt(i))));
		}
	}
	@Test
	public void test () {
		System.out.println(letterCombinations("999"));
	}
	
}
